﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Task02
{
    class Three
    {
        private List<Three> childs;
        public int Value;

        public int ChildsCount { get; private set; }

        public List<Three> Childs
        {
            get
            {
                if (childs == null)
                {
                    childs = new List<Three>();
                }
                return childs;
            }
        }

        public void ReadThreeFromConsole()
        {
            int n = int.Parse(Console.ReadLine());
            this.ChildsCount = n;
            for (int i = 0; i < n; i++)
            {
                Three three = new Three();
                three.Value = int.Parse(Console.ReadLine());
                three.ReadThreeFromConsole();
                this.ChildsCount += three.ChildsCount;
                this.Childs.Add(three);
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Three three = new Three();
            three.Value = int.Parse(Console.ReadLine());
            three.ReadThreeFromConsole();

            int needle = int.Parse(Console.ReadLine());

            ShowNodesWithNeedleCountOfSubNodes(needle, three);
        }

        private static void ShowNodesWithNeedleCountOfSubNodes(int needle, Three three)
        {
            Queue<Three> toVisit = new Queue<Three>();
            toVisit.Enqueue(three);

            while (toVisit.Count > 0)
            {
                Three currentThree = toVisit.Dequeue();
                if (currentThree.ChildsCount + 1 == needle)
                {
                    Console.WriteLine(currentThree.Value);
                }

                foreach (Three child in currentThree.Childs)
                {
                    toVisit.Enqueue(child);
                }
            }
        }
    }
}
